<template>
  <div class="account-settings-info-view">
    <el-row :gutter="16">
      <el-col :md="24" :lg="16">

        <el-form layout="vertical">
          <el-form-item
            label="昵称"
          >
            <el-input placeholder="给自己起个名字" />
          </el-form-item>
          <el-form-item
            label="电子邮件"
            :required="false"
          >
            <el-input placeholder="exp@admin.com" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary">提交</el-button>
            <el-button style="margin-left: 8px">保存</el-button>
          </el-form-item>
        </el-form>

      </el-col>
      <el-col :md="24" :lg="8" :style="{ minHeight: '180px' }">
        <div class="ant-upload-preview" @click="$refs.modal.edit(option.img)">
          <el-icon type="cloud-upload-o" class="upload-icon" />
          <div class="mask">
            <el-icon type="plus" />
          </div>
          <img :src="option.img">
        </div>
      </el-col>

    </el-row>

    <avatar-modal ref="modal" @ok="setavatar" />

  </div>
</template>

<script>
import AvatarModal from './AvatarModal'

export default {
  components: {
    AvatarModal
  },
  data() {
    return {
      // cropper
      option: {
        img: '/avatar2.jpg'
      }
    }
  },
  methods: {
    setavatar(url) {
      this.option.img = url
    }
  }
}
</script>

<style lang="scss" scoped>

  .avatar-upload-wrapper {
    height: 200px;
    width: 100%;
  }

  .ant-upload-preview {
    position: relative;
    margin: 0 auto;
    width: 100%;
    max-width: 180px;
    border-radius: 50%;
    box-shadow: 0 0 4px #ccc;

    .upload-icon {
      position: absolute;
      top: 0;
      right: 10px;
      font-size: 1.4rem;
      padding: 0.5rem;
      background: rgba(222, 221, 221, 0.7);
      border-radius: 50%;
      border: 1px solid rgba(0, 0, 0, 0.2);
    }
    .mask {
      opacity: 0;
      position: absolute;
      background: rgba(0,0,0,0.4);
      cursor: pointer;
      transition: opacity 0.4s;

      &:hover {
        opacity: 1;
      }

      i {
        font-size: 2rem;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-left: -1rem;
        margin-top: -1rem;
        color: #d6d6d6;
      }
    }

    img, .mask {
      width: 100%;
      max-width: 180px;
      height: 100%;
      border-radius: 50%;
      overflow: hidden;
    }
  }
</style>
